package com.imooc.articles_mongodb_project.controller;

import com.imooc.articles_mongodb_project.common.Result;
import com.imooc.articles_mongodb_project.common.validator.SaveValidator;
import com.imooc.articles_mongodb_project.dto.CommentDTO;
import com.imooc.articles_mongodb_project.service.ICommentsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@Api(tags = "评论数据的管理接口")
@RestController
@RequestMapping("/comments")
public class CommentController {

    @Autowired
    private ICommentsService commentsService;

    @ApiOperation(value = "新增评论数据")
    @PostMapping("/save")
    public Result save(@RequestBody @Validated(SaveValidator.class) CommentDTO commentDTO) {
        return commentsService.save(commentDTO);
    }


    @ApiOperation(value = "获取评论列表")
    @GetMapping("/list")
    public Result list() {
        return commentsService.getAll();
    }


    @ApiOperation(value = "根据文章id获取评论列表")
    @GetMapping("/getAllArticlesComments/{id}")
    public Result getAllArticlesComments(@PathVariable("id") String id) {
        return commentsService.getAllArticlesComments(id);
    }

    @ApiOperation(value = "根据评论id获取回复评论列表")
    @GetMapping("/getReplyComments/{id}")
    public Result getReplyComments(@PathVariable("id") String id) {
        return commentsService.getReplyComments(id);
    }


    @ApiOperation(value = "删除评论")
    @DeleteMapping("/removeComments/{id}")
    public Result removeComments(@PathVariable("id") String id) {
        return commentsService.removeComments(id);
    }
}
